package com.hsav.kcxb.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hsav.kcxb.R;
import com.hsav.kcxb.bean.WorkBean;
import com.hsav.kcxb.utils.ImgLoadUtil;

import java.util.List;

/**
 * Created by zhao on 2017/1/8.
 */

public class MyWorkAdapter extends BaseAdapter {

    private final Context mContext;
    private final List<WorkBean> mWorkBeanList;
    private final LayoutInflater mInflater;

    public MyWorkAdapter(Context context, List<WorkBean> workBeanList){
        this.mContext = context;
        this.mWorkBeanList = workBeanList;
        this.mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }
    @Override
    public int getCount() {
        if(mWorkBeanList!=null){
            return mWorkBeanList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if(mWorkBeanList!=null){
            return mWorkBeanList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView==null){
            convertView = mInflater.inflate(R.layout.item_work_view,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.headImg = (ImageView) convertView.findViewById(R.id.iv_work_head);
            viewHolder.nameTx = (TextView)convertView.findViewById(R.id.tv_work_name);
            viewHolder.titleTx = (TextView)convertView.findViewById(R.id.tv_work_title);
            viewHolder.dateTx = (TextView)convertView.findViewById(R.id.tv_work_date);
            viewHolder.descTx = (TextView)convertView.findViewById(R.id.tv_work_desc);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }
        WorkBean workBean = mWorkBeanList.get(position);
        viewHolder.nameTx.setText(workBean.getName());
        viewHolder.titleTx.setText(workBean.getTitle());
        viewHolder.dateTx.setText(workBean.getDate());
        viewHolder.descTx.setText(workBean.getDesc());
        ImgLoadUtil.setImage(mContext,viewHolder.headImg,workBean.getPicutre(),R.drawable.head);
        return convertView;
    }

    public class ViewHolder{
        ImageView headImg;
        TextView nameTx;
        TextView titleTx;
        TextView dateTx;
        TextView descTx;
    }
}
